<template>
  <div class="sys_menu">
    <el-container>
      <el-header>
        <header-item :item="tips"></header-item>
      </el-header>
      <el-main>
        <main-tools-item :toolsType="toolsType" @add='add'></main-tools-item>
        <main-spare-item @onClick=''></main-spare-item>
        <main-data-list-item :columns="columns" :dataList="dataList" :pager="page" @batchDelete='batchDelete' @currentChange='currentChange'>
          <el-table-column label="操作" slot="table_oper">
            <template slot-scope="scope">
              <el-button size="mini" type="success" @click="sysroleHandleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button size="mini" type="danger" @click="sysroleHandleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </main-data-list-item>
      </el-main>
    </el-container>
    <!--新增弹框 -->
    <el-dialog title="新增" :visible.sync="addDialogVisible" width="30%" @close="" close-on-press-escape close-on-click-modal class="defaultDialog">
      <el-form ref="addForm" :model="addForm" label-width="80px">
        <el-form-item label="设备名称">
          <el-input v-model="addForm.deviceName"></el-input>
        </el-form-item>
        <el-form-item label="设备描述">
          <el-input v-model="addForm.deviceDesc"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="addSumbit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--编辑弹框 -->
    <el-dialog title="编辑" :visible.sync="editDialogVisible" width="30%" @close="" close-on-press-escape close-on-click-modal class="defaultDialog">
      <el-form ref="editForm" :model="editForm" label-width="80px">
        <el-form-item label="设备名称">
          <el-input v-model="editForm.deviceName"></el-input>
        </el-form-item>
        <el-form-item label="设备描述">
          <el-input v-model="editForm.deviceDesc"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="editSumbit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {
    get,
    post,
    pat,
    del,
    common,
    getRefresh
  } from "../../../../api/api";
  import headerItem from "./../../Commons/headerItem.vue";
  import mainToolsItem from "./../../Commons/mainToolsItem.vue";
  import mainSpareItem from "./../../Commons/mainSpareItem.vue";
  import mainDataListItem from "./../../Commons/mainDataListItem.vue";
  export default {
    components: {
      headerItem,
      mainToolsItem,
      mainSpareItem,
      mainDataListItem
    },
    data() {
      return {
        tips: "菜单管理",
        toolsType: 3,
        sels: [],
        page: {
          pageNo: 1,
          limit: 10,
          sizes: [10, 50, 100],
          total: 0
        },
        columns: [{
            prop: 'id',
            label: 'id',
            width: '150',
            align: 'center'
          },
          {
            prop: 'username',
            label: '姓名',
            width: '200',
            align: 'center',
            // formatter: this.formatter
          },
          {
            prop: 'created_at',
            label: '创建时间',
            width: '200',
            align: 'center'
          },
          {
            prop: 'updated_at',
            label: '更新时间',
            width: '200',
            align: 'center'
          }
        ],
        dataList: [{
            id: 1,
            username: 'sys_menu_xxy',
            created_at: "2019-03-01",
            updated_at: "2018-05-03"
          },
          {
            id: 2,
            username: 'sys_menu_xxy',
            created_at: "2019-03-01",
            updated_at: "2018-05-03"
          },
          {
            id: 3,
            username: 'sys_menu_xxy',
            created_at: "2019-03-01",
            updated_at: "2018-05-03"
          }
        ],
        addDialogVisible: false,
        addForm: {},
        editDialogVisible:false,
        editForm: {},
      };
    },
    methods: {
      //--------新增----------
      add() {
        this.addDialogVisible = true;
      },
      addSumbit() {
        this.addDialogVisible =false;
      },
      //--------编辑----------
      sysroleHandleEdit() {
        this.editDialogVisible = true;
      },
      editSumbit(){
        this.editDialogVisible = false;
      },
      //--------删除----------
      sysroleHandleDelete() {},
      batchDelete(val){
        console.log(val);
      },
      //-------分页----------
      currentChange(val){
        console.log(val);
      },
      //获取list列表
      getGroupList() {
        return new Promise((resolve, reject) => {
          get("/sys/groups").then(resdata => {
            let self = function () {
              this.$router.push({ path: '/home'});
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 0) {

              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
    },
    async mounted() {
      // await this.$store.dispatch("userInfo", this);
      // await this.getGroupList();
      // await this.getChangeGroupList();
      // setTimeout(() => {}, 1000);
    },
    watch: {
      // filterText(val) {
      //   this.$refs.tree2.filter(val);
      // }
    }
  };

</script>

<style lang="scss">
  .sys_menu {
    background-color: white;
    font-size: 1.8rem;
    width: 100%;
    height: 100%;
    .el-container {
      height: 100%;
      .el-header,
      .el-footer {
        background-color: #F9FAFE;
        color: #333;
        text-align: center;
        line-height: 50px;
        height: 50px !important;
        .header-child {
          height: 50px;
          width: 100%;
          text-align: left;
          padding-left: 20px;
          background-color: #cbe9eb;
          border-bottom: 1px solid black;
          box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
        } 
      }
      .el-main {
        box-shadow: 0 5px 5px 0px rgba(0, 0, 0, 0.5); // margin: 10px 20px;
        margin: 10px;
        background-color: #fff;
        color: #333;
        text-align: center;
        height: 100%;
      }
    }

    /* 弹框CSS*/
    .defaultDialog {
      .el-dialog {
        box-shadow: 0px 5px 15px 0 rgba(0, 0, 0, 0.5);
        border-radius: 5px;
        .el-dialog__header {
          text-align: left;
          .el-dialog__title {
            font-family: "Roboto", sans-serif;
            color: #7d7d7d;
            font-size: 15px;
          }
        }
        .el-dialog__body {
          .el-form {
            padding-left: 40px;
            .el-form-item {
              width: 80%;
              .el-form-item__content {
                text-align: left;
              }
              .el-form-item__label {
                padding: 0 24px 0 0;
                color: #333;
                font-weight: 400;
                font-size: 13px;
              }
            }
          }
        }
      }
    }
  }

</style>
